home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Differential Equations / Multimedia Differential Equations.ISO / progfile.sfs / LAUNCHER.PAS < prev    next >
Pascal/Delphi Source File  |  1996-08-15  |  3KB  |  114 lines

  1. program Launcher;
  2.  
  3. uses
  4.   WinTypes, WinProcs, IniFiles, SysUtils;
  5.  
  6. {$R *.RES}
  7.  
  8. Const
  9.   cProductIdFileName = 'ID911271.ID_';  { !!! MUST match PRODUCT_ID_FILENAME in CUSTOM.RUL !!! }
  10.   cProgramKeyName    = '91127-1';       { !!! MUST match APP_UPC_CODE in CUSTOM.RUL !!! }
  11.   cSectionName       = 'Sofsource';     { !!! MUST match PROGRAM_FOLDER_NAME in CUSTOM.RUL !!! }
  12.  
  13.   cPermanentSetupLog = 'SOF_LOG_.INI';  { Don't change this value }
  14.  
  15.  
  16. const
  17.   DosDelimSet : set of Char = ['\', ':', #0];
  18.  
  19.  
  20. Var
  21.   IniLog : TIniFile;
  22.   FileToFind,
  23.   RecordedDestination : String;
  24.  
  25.  
  26.  
  27. Function AddBackSlash( Const DirName : String ) : String;
  28.   { Add a default backslash to a directory name }
  29. Begin
  30.  
  31.   If DirName[ Length(DirName) ] in DosDelimSet Then
  32.     AddBackSlash := DirName
  33.   ELSE
  34.     AddBackSlash := DirName + '\';
  35.  
  36. End; { Function AddBackSlash }
  37.  
  38.  
  39.  
  40. Function JustPathname( Const PathName : String ) : String;
  41.   { Return just the drive:directory portion of a pathname }
  42. Var
  43.   I : Word;
  44. Begin
  45.  
  46.   I := Succ( Word( Length(PathName) ) );
  47.   Repeat
  48.     Dec(I);
  49.   Until (PathName[I] in DosDelimSet) or (I = 0);
  50.  
  51.   If I = 0 Then { Had no drive or directory name }
  52.     JustPathname[0] := #0              
  53.   ELSE
  54.     If I = 1 Then { Either the root directory of default drive or invalid pathname }
  55.       JustPathname := PathName[1]      
  56.     ELSE
  57.       If (PathName[I] = '\') Then
  58.       Begin
  59.         If PathName[Pred(I)] = ':' Then { Root directory of a drive, leave trailing backslash }
  60.           JustPathname := Copy(PathName, 1, I)   
  61.         ELSE { Subdirectory, remove the trailing backslash }
  62.           JustPathname := Copy(PathName, 1, Pred(I)); 
  63.       End
  64.       ELSE { Either the default directory of a drive or invalid pathname }
  65.         JustPathname := Copy(PathName, 1, I);
  66.  
  67. End; { Function JustPathName }
  68.  
  69.  
  70.  
  71. Procedure LaunchSetup;
  72. Var
  73.   FileToExecute  : String;
  74.   pFileToExecute : Array[0..254] of Char;
  75. Begin
  76.  
  77.   FileToExecute := AddBackSlash( JustPathName( ParamStr(0)) );
  78.  
  79.   ChDir( FileToExecute );
  80.                    
  81.   FileToExecute := AddBackSlash( FileToExecute) + 'SETUP.EXE AUTOPLAY';
  82.                   
  83.   StrPCopy( pFileToExecute, FileToExecute );
  84.  
  85.   If WinExec( pFileToExecute, sw_ShowNormal ) < 32 Then
  86.   Begin
  87.     MessageBeep( mb_IconHand );
  88.     MessageBox( 0, 'Unable to launch "SETUP.EXE"', 'Error', 0 );
  89.   End;        
  90.  
  91. End; { Procedure LaunchSetup }
  92.  
  93.  
  94.  
  95. begin
  96.  
  97.   IniLog := TIniFile.Create( cPermanentSetupLog );
  98.   RecordedDestination := IniLog.ReadString( cSectionName, cProgramKeyName, '' );
  99.   IniLog.Free;
  100.  
  101.   If RecordedDestination = '' Then
  102.     LaunchSetup
  103.   ELSE
  104.   Begin
  105.  
  106.     FileToFind := AddBackSlash( RecordedDestination ) + cProductIdFileName;
  107.  
  108.     If NOT FileExists( FileToFind ) Then
  109.       LaunchSetup;
  110.  
  111.   End;
  112.  
  113. end.
  114.